import { $wuxPicker } from '../../../dist/wux'
function a(a) {
    return a && a.__esModule ? a : {
        default: a
    }
}
a(require("../../../helpers/WxValidate"));
var n = a(require("../../../json/cate.js")),
    e = (a(require("../../../etc/config")), getApp());

    // 年龄段和身高区间循环计算
for (var t = a(require("../../../json/cate.js")),
low = [{
    value: 0,
    name: "不限"
}],
high = [{
    value: 0,
    name: "不限"
}],
i = 18; i <= 99; i++) low.push({
value: i,
name: i
});
for (var v = 19; v <= 99; v++) high.push({
value: v,
name: v
});
// 拿到所有数组的name赋值给r数组
for (var r = low.map(function (a) {
return a.name
}), u = high.map(function (a) {
return a.name
}), l = [{
value: 0,
name: "不限"
}], h = [{
value: 0,
name: "不限"
}], d = 150; d <= 210; d++) l.push({
value: d,
name: d
});
for (var s = 151; s <= 210; s++) h.push({
value: s,
name: s
});
var f = l.map(function (a) {
return a.name
}),
g = h.map(function (a) {
return a.name
});

const app = getApp()

// r-u是年龄段,f-g是身高区间
import http from '../../util/request.js';
Page({
    data: {
        noteMaxLen: 200,
        currentNoteLen: 0,
        cate: {},
        form: {},
        //地址帅选 start
        address1: "请选择",
        cityindex: 0,
        areaindex: 0,
        city: [],
        multiIndex: [0, 0],
        area: 0,
        //地址帅选 end
        region: [],
        customItem: '不限'
    },
    onLoad: function (t) {
        var a = this;
        a.setData({
            t: t.t
        });
        if (t.t == 1) {
            wx.setNavigationBarTitle({
                title: '择偶标准',
            })
        } else {
            wx.setNavigationBarTitle({
                title: '设置基本信息',
            })
        }
        this.getcity();
        http.get('config').then(data => {
            a.setData({
                citys: data.citys,
                xinyang: data.xinyang
            });
            var def = n.default;
            console.log(n)
            a.setData({
                cate: def
            });
            a.getCate();
        });
        http.get('user', {
            uid: wx.getStorageSync("user").id
        }).then(data => {
            console.log(data)
            a.setData({
                user: data
            });
            a.setData({
                avatar: data.avatar,
                "form": data
            });

        });
    },
    onShow: function () {

    },
    bindPickerChange: function (a) {
        this.setData({
            index: a.detail.value
        })
    },
    getCate: function () {
        for (var t = this.data.cate, a = [{
                value: 0,
                name: "请选择"
            }], e = [{
                value: 0,
                name: "请选择"
            }], i = 150; i <= 210; i++) a.push({
            value: i,
            name: i + "cm"
        });
        for (i = 30; i <= 150; i++) 30 == i && e.push({
            value: i,
            name: i + "以下kg"
        }), e.push({
            value: i,
            name: i + "kg"
        }), 150 == i && e.push({
            value: i,
            name: i + "以上kg"
        });
        t = {
            genderData: n.
            default.genderData,
            genderArr: n.
            default.genderData.map(function (t) {
                return t.name
            }),
            genderActionIndex: 0,
            constellationData: n.
            default.constellationData,
            constellationArr: n.
            default.constellationData.map(function (t) {
                return t.name
            }),
            constellationActionIndex: 0,
            heightData: a,
            heightArr: a.map(function (t) {
                return t.name
            }),
            heightActionIndex: 0,
            weightData: e,
            weightArr: e.map(function (t) {
                return t.name
            }),
            weightActionIndex: 0,
            salaryData: n.
            default.salaryData,
            salaryArr: n.
            default.salaryData.map(function (t) {
                return t.name
            }),
            salaryActionIndex: 0,
            eduData: n.
            default.eduData,
            eduArr: n.
            default.eduData.map(function (t) {
                return t.name
            }),
            eduActionIndex: 0,
            marriageData: n.
            default.marriageData,
            marriageArr: n.
            default.marriageData.map(function (t) {
                return t.name
            }),
            marriageActionIndex: 0,
            childrenData: n.
            default.childrenData,
            childrenArr: n.
            default.childrenData.map(function (t) {
                return t.name
            }),
            childrenActionIndex: 0,
            bodyData: n.
            default.bodyData,
            bodyArr: n.
            default.bodyData.map(function (t) {
                return t.name
            }),
            bodyActionIndex: 0,
            wantchildrenData: n.
            default.wantchildrenData,
            wantchildrenArr: n.
            default.wantchildrenData.map(function (t) {
                return t.name
            }),
            wantchildrenActionIndex: 0,
            occupationData: n.
            default.occupationData,
            occupationArr: n.
            default.occupationData.map(function (t) {
                return t.name
            }),
            occupationActionIndex: 0,
            vehicleData: n.
            default.vehicleData,
            vehicleArr: n.
            default.vehicleData.map(function (t) {
                return t.name
            }),
            vehicleActionIndex: 0,
            houseData: n.
            default.houseData,
            houseArr: n.
            default.houseData.map(function (t) {
                return t.name
            }),
            houseActionIndex: 0,
            drinkingData: n.
            default.drinkingData,
            drinkingArr: n.
            default.drinkingData.map(function (t) {
                return t.name
            }),
            drinkingActionIndex: 0,
            smokingData: n.
            default.smokingData,
            smokingArr: n.
            default.smokingData.map(function (t) {
                return t.name
            }),
            smokingActionIndex: 0,
            stockData: n.
            default.stockData,
            stockArr: n.
            default.stockData.map(function (t) {
                return t.name
            }),
            stockActionIndex: 0,
            marryData: n.
            default.marryData,
            marryArr: n.
            default.marryData.map(function (t) {
                return t.name
            }),
            marryActionIndex: 0,
            showinfoData: n.
            default.showinfoData,
            showinfoArr: n.
            default.showinfoData.map(function (t) {
                return t.name
            }),
            showinfoActionIndex: 0
        }, this.setData({
            cate: t
        })
        console.log(t)
    },
    //地址帅选 start
    bindMultiPickerColumnChange: function (t) {
        console.log("修改的列为", t.detail.column, "，值为", t.detail.value);
        var a = this,
            e = {
                city: a.data.city,
                multiIndex: a.data.multiIndex
            };
        e.multiIndex[t.detail.column] = t.detail.value;
        var i = a.data.city_id;
        switch (t.detail.column) {
            case 0:
                var n = a.data.city[0][t.detail.value].id;
                i != n && a.searchClassInfo(n), e.multiIndex[1] = 0;
        }
    },
    bindMultiPickerChange: function (t) {
        var a = this;
        if (t.detail.value[0] == 0) {
            a.setData({
                address1: '请选择'
            });
        } else {
            a.setData({
                "form.workCityString": a.data.city[0][t.detail.value[0]].name + ',' + a.data.city[1][t.detail.value[1]].name
            });
        }
    },
    searchClassInfo: function (t) {
        var a = this;
        http.get("getcity", {
            pid: t
        }).then(data => {
            a.setData({
                city: data
            });
        });
    },
    getcity: function () {
        var t = this;
        http.get("getcity", {
            pid: 0
        }).then(data => {
            t.setData({
                city: data
            });
        });
    },
    //地址帅选 end
    onWorkCity: function (t) {
        this.setData({
            "form.workCityString": this.data.citys[t.detail.value],
        })
    },
    onXin6yang: function (t) {
        this.setData({
            "form.xinyang": this.data.xinyang[t.detail.value],
        })
    },
    onFromCity: function () {
        var a = this;
        this.$wuxPickerCity.init("city", {
            title: "请选择籍贯",
            value: a.data.form.hometown.split(","),
            onChange: function (a) {
                this.setData({
                    "form.hometownString": a.text,
                    "form.hometown": a.value.join(",")
                })
            }
        })
    },
    onBirth: function (a) {
        this.setData({
            "form.birth": a.detail.value
        })
    },
    onAgeRange: function () {
        var a = this;
        $wuxPicker.init(
            "ageRange", {
            title: "请选择年龄范围",
            cols: [{
                textAlign: "center",
                values: r
            }, {
                textAlign: "center",
                values: u
            }],
            value: a.data.form.ageRangeKey,
            onChange: function (t) {
                var e = [];
                // 如果满足条件:循环遍历r数组,当前选项值等于第一列传入的value值且
                if (r.forEach(function (a, n) {a === t.value[0] && (e[0] = n)}), 
                    u.forEach(function (a, n) {a === t.value[1] && (e[1] = n)}),
                    // 第一行不是不限 
                    "不限" != t.value[0]) {
                // 执行以下方法
                // 循环出一个n数组,大于r数组1,小于等于99
                    for (var n = ["不限"], o = parseInt(t.value[0] + 1); o <= 99; o++) n.push(o);
                    a.data.startAgeString != t.value[0] && t.value[0] >= t.value[1] ? (t.value[1] = n[2], e[1] = 2) : n.forEach(function (a, n) {
                        a == t.value[1] && (t.value[1] = a, e[1] = n)
                    }), u = n
                } else {
                    for (var i = ["不限"], c = 19; c <= 99; c++) i.push(c);
                    i.forEach(function (a, n) {
                        a == t.value[1] && (t.value[1] = a, e[1] = n)
                    }), u = i
                }
                this.options.data.cols[1].values = u;
                // 拼接年龄
                var l = "不限";
                l = "不限" == t.value[0] && "不限" == t.value[1] ? "不限" : "不限" == t.value[1] ? t.value[0] + "岁以上" : "不限" == t.value[0] && "不限" != t.value[1] ? t.value[1] + "岁以下" : t.value.join("-") + "岁",
                 this.setData({
                    startAgeString: t.value[0],
                    "$wux.picker.ageRange.cols": this.options.data.cols,
                    "$wux.picker.ageRange.value": e || 0,
                    "form.objectAge1": t.value[0],
                    "form.objectAge2": t.value[1],
                    "form.objectAgeString": l
                })
            }
        },
        console.log('diaoyong')
        )
    },
    onHeightRange: function () {
        var a = this;
        $wuxPicker.init("heightRange", {
            title: "请选择身高范围",
            cols: [{
                textAlign: "center",
                values: f
            }, {
                textAlign: "center",
                values: g
            }],
            value: a.data.form.heightRangeKey,
            onChange: function (t) {
                var e = [];
                if (f.forEach(function (a, n) {
                        a === t.value[0] && (e[0] = n)
                    }), g.forEach(function (a, n) {
                        a === t.value[1] && (e[1] = n)
                    }), "不限" != t.value[0]) {
                    for (var n = ["不限"], o = parseInt(t.value[0] + 1); o <= 210; o++) n.push(o);
                    a.data.minHeightString != t.value[0] && t.value[0] >= t.value[1] ? (t.value[1] = n[2], e[1] = 2) : n.forEach(function (a, n) {
                        a == t.value[1] && (t.value[1] = a, e[1] = n)
                    }), g = n
                } else {
                    for (var i = ["不限"], c = 151; c <= 210; c++) i.push(c);
                    i.forEach(function (a, n) {
                        a == t.value[1] && (t.value[1] = a, e[1] = n)
                    }), g = i
                }
                this.options.data.cols[1].values = g;
                var r = "不限";
                r = "不限" == t.value[0] && "不限" == t.value[1] ? "不限" : "不限" == t.value[1] ? t.value[0] + "cm以上" : "不限" == t.value[0] && "不限" != t.value[1] ? t.value[1] + "cm以下" : t.value.join("-") + "cm", this.setData({
                    minHeightString: t.value[0],
                    "$wux.picker.heightRange.cols": this.options.data.cols,
                    "$wux.picker.heightRange.value": e || 0,
                    "form.objectHeight1": t.value[0],
                    "form.objectHeight2": t.value[1],
                    "form.objectHeightString": r
                })
            }
        })
    },
    onMarry: function (a) {
        this.setData({
            "cate.marryActionIndex": a.detail.value,
            "form.marryDateString": this.data.cate.marryData[a.detail.value].name,
            "form.marryDate": this.data.cate.marryData[a.detail.value].value
        })
    },
    onShowinfo: function (a) {
        this.setData({
            "cate.showinfoActionIndex": a.detail.value,
            "form.showinfoDataString": this.data.cate.showinfoData[a.detail.value].name,
            "form.showinfoData": this.data.cate.showinfoData[a.detail.value].value
        })
    },
    onStock: function (a) {
        this.setData({
            "cate.stockActionIndex": a.detail.value,
            "form.stockString": this.data.cate.stockData[a.detail.value].name,
            "form.stock": this.data.cate.stockData[a.detail.value].value
        })
    },
    onConstellation: function (a) {
        this.setData({
            "cate.constellationActionIndex": a.detail.value,
            "form.constellationString": this.data.cate.constellationData[a.detail.value].name,
            "form.constellation": this.data.cate.constellationData[a.detail.value].value
        })
    },
    onDrinking: function (a) {
        this.setData({
            "cate.drinkingActionIndex": a.detail.value,
            "form.objectIsDrinkingString": this.data.cate.drinkingData[a.detail.value].name,
            "form.drinking": this.data.cate.drinkingData[a.detail.value].value
        })
    },
    onSmoking: function (a) {
        this.setData({
            "cate.smokingActionIndex": a.detail.value,
            "form.objectIsSmokingString": this.data.cate.smokingData[a.detail.value].name,
            "form.smoking": this.data.cate.smokingData[a.detail.value].value
        })
    },
    onSex: function () {
        return e.WxService.showModal({
            title: "温馨提示",
            cancelText: "取消",
            confirmText: "知道了",
            content: "修改性别请联系客服微信，工作人员将会协助您修改"
        })
    },
    onBirthday: function () {
        return e.WxService.showModal({
            title: "温馨提示",
            cancelText: "取消",
            confirmText: "知道了",
            content: "修改生日请" + this.data.form.kf_text + "，工作人员将会协助您修改"
        })
    },
    onPhone: function () {
        return wx.showModal({
            title: "温馨提示",
            content: "请先保存好其它信息",
            cancelText: "去保存",
            confirmText: "已保存",
            success: function (a) {
                a.confirm ? wx.navigateTo({
                    url: "/pages/u/settings/editmobile"
                }) : a.cancel && console.log("用户点击取消")
            }
        })
    },
    onGender: function (a) {
        console.log(this.data.form.ischeck), 0 == !this.data.form.ischeck || this.setData({
            "cate.genderActionIndex": a.detail.value,
            "form.genderString": this.data.cate.genderData[a.detail.value].name,
            "form.gender": this.data.cate.genderData[a.detail.value].value
        })
    },
    onWeight: function (a) {
        this.setData({
            "cate.weightActionIndex": a.detail.value,
            "form.weight": this.data.cate.weightData[a.detail.value].value
        })
    },
    onHeight: function (a) {
        this.setData({
            "cate.heightActionIndex": a.detail.value,
            "form.height": this.data.cate.heightData[a.detail.value].value,
            "form.heightString": this.data.cate.heightData[a.detail.value].name
        })
    },
    onSalary: function (a) {
        this.setData({
            "cate.salaryActionIndex": a.detail.value,
            "form.objectSalaryString": this.data.cate.salaryData[a.detail.value].name,
            "form.salary": this.data.cate.salaryData[a.detail.value].value
        })
    },
    onEdu: function (a) {
        this.setData({
            "cate.eduActionIndex": a.detail.value,
            "form.objectEducationString": this.data.cate.eduData[a.detail.value].name,
            "form.education": this.data.cate.eduData[a.detail.value].value
        })
    },
    onMarriage: function (a) {
        this.setData({
            "cate.marriageActionIndex": a.detail.value,
            "form.objectMarriageString": this.data.cate.marriageData[a.detail.value].name,
            "form.marriage": this.data.cate.marriageData[a.detail.value].value
        })
    },
    onChildren: function (a) {
        this.setData({
            "cate.childrenActionIndex": a.detail.value,
            "form.childrenString": this.data.cate.childrenData[a.detail.value].name,
            "form.children": this.data.cate.childrenData[a.detail.value].value
        })
    },
    onWantchildren: function (a) {
        this.setData({
            "cate.wantchildrenActionIndex": a.detail.value,
            "form.wantChildrenString": this.data.cate.wantchildrenData[a.detail.value].name,
            "form.wantChildren": this.data.cate.wantchildrenData[a.detail.value].value
        })
    },
    onOccupation: function (a) {
        this.setData({
            "cate.occupationActionIndex": a.detail.value,
            "form.occupationString": this.data.cate.occupationData[a.detail.value].name,
            "form.occupation": this.data.cate.occupationData[a.detail.value].value
        })
    },
    onVehicle: function (a) {
        this.setData({
            "cate.vehicleActionIndex": a.detail.value,
            "form.vehicleString": this.data.cate.vehicleData[a.detail.value].name,
            "form.vehicle": this.data.cate.vehicleData[a.detail.value].value
        })
    },
    onHouse: function (a) {
        this.setData({
            "cate.houseActionIndex": a.detail.value,
            "form.houseString": this.data.cate.houseData[a.detail.value].name,
            "form.house": this.data.cate.houseData[a.detail.value].value
        })
    },
    // onBody: function(a) {
    //     this.setData({
    //         "cate.bodyActionIndex": a.detail.value,
    //         "form.bodyString": this.data.cate.bodyData[a.detail.value].name,
    //         "form.body": this.data.cate.bodyData[a.detail.value].value
    //     })
    // },
    renderForm: function () {
        var a = this;
        this.info.getAsync({
            action: "do"
        }).then(function (t) {
            if (200 == t.code) {
                var e = a.userinfo = t.data.userinfo;
                a.getCate();
                var n = a.data.cate;
                n.genderData.forEach(function (a, t) {
                    a.value == e.gender && (n.genderActionIndex = t)
                }), n.heightData.forEach(function (a, t) {
                    a.value === e.height && (n.heightActionIndex = t)
                }), n.salaryData.forEach(function (a, t) {
                    a.value === e.salary && (n.salaryActionIndex = t)
                }), n.eduData.forEach(function (a, t) {
                    a.value === e.education && (n.eduActionIndex = t)
                }), n.marriageData.forEach(function (a, t) {
                    a.value === e.marriage && (n.marriageActionIndex = t)
                }), n.childrenData.forEach(function (a, t) {
                    a.value === e.children && (n.childrenActionIndex = t)
                }), n.wantchildrenData.forEach(function (a, t) {
                    a.value == e.wantChildren && (n.wantchildrenActionIndex = t)
                }), n.occupationData.forEach(function (a, t) {
                    a.value == e.occupation && (n.occupationActionIndex = t)
                }), n.vehicleData.forEach(function (a, t) {
                    a.value == e.vehicle && (n.vehicleActionIndex = t)
                }), n.houseData.forEach(function (a, t) {
                    a.value == e.house && (n.houseActionIndex = t)
                }), n.weightData.forEach(function (a, t) {
                    a.value == e.weight && (n.weightActionIndex = t)
                }), n.smokingData.forEach(function (a, t) {
                    a.value == e.smoking && (n.smokingActionIndex = t)
                }), n.drinkingData.forEach(function (a, t) {
                    a.value == e.drinking && (n.drinkingActionIndex = t)
                }), n.constellationData.forEach(function (a, t) {
                    a.value == e.constellation && (n.constellationActionIndex = t)
                }), n.stockData.forEach(function (a, t) {
                    a.value == e.stock && (n.stockActionIndex = t)
                }), n.marryData.forEach(function (a, t) {
                    a.value == e.marryDate && (n.marryActionIndex = t)
                }), n.showinfoData.forEach(function (a, t) {
                    a.value == e.showinfoData && (n.showinfoActionIndex = t)
                }), a.setData({
                    form: e,
                    cate: n
                })
            }
        })
    },
    inputNickname: function (a) {
        this.setData({
            "form.nickname": a.detail.value
        })
    },
    getInfoState: function (a) {
        console.log("switch1 发生 change 事件，携带值为", a.detail.value)
    },
    submitForm: function (t) {
        var a = this;
        var e = Object.assign(this.data.form, t.detail.value);
        console.log(e);
        if (a.data.t == 1) {
            /*
            if ("" == e.birth) {
              a.showToastErr("请选择出生年月");
              return false;
            }
            if ("" == e.heightString) {
              a.showToastErr("请选择身高");
              return false;
            }
            if (e.salaryString == "") {
              a.showToastErr("请选择月收入");
              return false;
            }
            if (e.educationString == "") {
              a.showToastErr("请选择学历");
              return false;
            }
            if (e.marriageString == "") {
              a.showToastErr("请选择婚姻状况");
              return false;
            }
            */
        } else {
            /*
            if (e.workCityString == "") {
              a.showToastErr("请选择工作地区");
              return false;
            }

            if (e.childrenString == "") {
              a.showToastErr("请选择有没有小孩");
              return false;
            }
            if (e.occupationString == "") {
              a.showToastErr("请选择职业");
              return false;
            }
            if (e.wantChildrenString == "") {
              a.showToastErr("请选择是否想要小孩");
              return false;
            }
            */
        }

        http.post('saveuser1', e).then(data => {
            a.showToastSuc("保存成功");
            setTimeout(function () {
                wx.redirectTo({
                    url: '../edit/index',
                })
            }, 1500);
        });
    },
    showToastSuc: function (t) {
        wx.showToast({
            title: t,
            duration: 1500,
            icon: 'sucess'
        });
    },
    showToastErr: function (t) {
        wx.showToast({
            title: t,
            duration: 1500,
            icon: "none"
        });
    },
    showToastCancel: function (a) {
        this.$wuxToast.show({
            type: "cancel",
            timer: 1500,
            color: "#fff",
            text: "" + a
        })
    },
    bindRegionChange: function (e) {
        var region = e.detail.value[2] == '不限' ? '' : ',' + e.detail.value[2]
        this.setData({
            "form.workCityString": e.detail.value[0] + ',' + e.detail.value[1] + region
        })
    },
});